<%@ page language="java" import="java.util.*,java.net.*" contentType="text/html; charset=utf-8"  pageEncoding="utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>学生授权登录</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	
	<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
	<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript">
			$(document).ready(function(){
				$("#submit").click(function(){
					$.ajax({
					type: "POST", //访问WebService使用Post方式请求
					url: "interface/stuLogin", //调用WebService的地址和方法名称组合 ---- WsURL/方法名
					data: $("#userform").serialize(), //这里是要传递的参数，格式为 data: "{paraName:paraValue}",下面将会看到
					dataType: 'json', //WebService 会返回Json类型
					success: function(json) {
							if (json.result == "success") {
								var callback = json.data.callback
								var uid = json.data.uid
								var url = callback.indexOf('?') == -1 ? callback + "?uid=" + uid : callback + "&uid=" + uid; 
								location.href= (url)
							}else{
								alert(json.data)
								validate_refrash()
							}
						},
					error:function(){
								alert("unknown error")
								validate_refrash()
						}
					});
				});
				$("#validate").keydown(function(e){
					if(e.keyCode == 13) {
						$("#submit").click();
					}
				});
			});
			function validate_refrash(){
				$("#validateCode").attr("src", "validate_code?" + Math.floor(Math.random()*100))
			}
			
	</script>
	
	<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
	<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
	<!-- <link href='http://fonts.useso.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'> -->
  </head>
  
  <body>
    <form id="userform">
    <input type="hidden" name="accessToken" value="${requestScope.accessToken}"/>
    <input type="hidden" name="callback" value="${requestScope.callback}"/>
    <div class="contact" style="padding-top:10%; height:100%; background-position: top;"><div class="container">
    	<div class="contact-form">
			<div class="contact-left" style="margin-left:38%">
				<input id="username" name="username" type="text" placeholder="学生学号" required>
				<input id="password" name="password" type="password" placeholder="教务系统密码" required>
				<input id="validate" name="validate" type="text" placeholder="验证码" style="width:52%; margin-right:5px;" required>
				<img id="validateCode" title="refrash"  src="validate_code" onclick="validate_refrash()"/>
				<input id="submit" type="button" value="授权" style="margin-bottom:15px">
			</div>
		</div>
    </div></div>
    </form>
  </body>
</html>
